//
//  CNLandmarkList.swift
//  SwiftUi
//
//  Created by xm on 29/08/2025.
//

import SwiftUI

struct CNLandmarkList: View {
    
    @State private var showFavoritesOnly = false
    @EnvironmentObject var userData: UserData

    var body: some View {
        NavigationStack{
            
            List {
                Toggle(isOn: $showFavoritesOnly) { // 绑定类型加$
                    Text("只显示收藏")
                }
                ForEach(userData.landmarks) { landmark in

                    if !showFavoritesOnly || landmark.isFevorite {
                        NavigationLink(destination: {
                            CNLandmarkDetail(landmark: landmark)
                        }){
                            CNLandmarkCell(landmark: landmark).frame(height: 50)
                        }
                    }
                  
                }
                
            }
            .navigationBarTitle(Text("中国地标"))
                .padding(-18)
                .padding(.top, 20)
                
        }
    }
}

#Preview {
    CNLandmarkList()
}


